package org.feit.findword.game;

import java.util.HashSet;
import java.util.Set;
import org.feit.findword.trie.TransitionMap;

public abstract class Board implements TransitionMap {
	private String[] board;
	private Set<String> mVocals;

	public Board(String[] b, boolean isMK) {
		board = b;
		mVocals = new HashSet<String>();
		if (isMK) { // mk language
			mVocals.add("А");
			mVocals.add("Е");
			mVocals.add("И");
			mVocals.add("О");
			mVocals.add("У");
		} else {
			mVocals.add("A");
			mVocals.add("E");
			mVocals.add("I");
			mVocals.add("O");
			mVocals.add("U");
		}
	}

	public synchronized String elementAt(int i) {
		return board[i];
	}

	public synchronized String elementAt(int x, int y) {
		return board[x + getWidth() * y];
	}

	public synchronized boolean isVocal(int i) {
		return mVocals.contains(board[i]);
	}

	public synchronized char valueAt(int i) {
		return board[i].charAt(0);
	}

	public synchronized String toString() {
		StringBuilder sb = new StringBuilder();
		int size = getSize();
		for (int i = 0; i < size - 1; i++) {
			sb.append(board[i]);
			sb.append(",");
		}
		sb.append(board[size - 1]);

		return sb.toString();
	}

	public synchronized void rotate() {
		String[] newbrd = new String[getSize()];

		int w = getWidth();

		for (int i = 0; i < getSize(); i++) {
			newbrd[w * (i % w) + ((w - 1) - (i / w))] = board[i];
		}

		board = newbrd;
	}

	public abstract int getSize();

	public abstract int getWidth();

	public abstract long transitions(int position);

}
